from pathlib import PurePath

import httpx
from anyio import run

from my_webdav.resource_model.drive_115.dependency import DBSession, refresh_115_cache
from my_webdav.resource_model.drive_115.data_operate import OperateLayer, CacheLayer, ClientFor115
from my_webdav.config import app_setting

# 测试用pickcode
TEST_PC_1 = "a8kuim2kw3jtjhjld"  # 小文件 文本
TEST_PC_2 = "alvwuwkf6e4jwhjld"  # 视频


async def main():
    root_id = app_setting.PAN_115_ROOT_CID
    cookie = app_setting.PAN_115_COOKIE
    mount_path = app_setting.PAN_115_MOUNT_PATH

    await refresh_115_cache()

    async with httpx.AsyncClient() as a_client:
        with httpx.Client() as s_client:
            async with DBSession.begin() as session:
                c_115 = ClientFor115(root_id, cookie, a_client, s_client, 5.0)
                cache = CacheLayer(session)
                op_layer = OperateLayer(c_115, cache)
                # members = await op_layer.search_until_find(
                #     PurePath("/dav_115/test_folder/inner_folder_2/test_vid_2.mp4"),
                #     0,
                #     PurePath("/dav_115")
                # )
                members = await op_layer.search_until_find(
                    PurePath("/dav_115/test_folder/inner_folder_2"),
                    1,
                    PurePath("/dav_115")
                )
    return members

res = run(main)
